<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>注册中心</title>
    <link rel="stylesheet" type="text/css" href="{MODULE_URL}template/mobile/style/style1/static/css/weui.css" />
    <script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/jquery-1.11.1.min.js"></script>
    <style type="text/css">
    body {
        background-color: #efeef4;
    }
    
    .weui_label {
        font-size: 14px;
        color: #a9a9a9;
        width: 5em;
    }
    
    .weui_textarea .weui_select .weui_input {
        font-size: 12px;
        color: #a9a9a9;
    }
    </style>
</head>

<body>
    <div class="weui_cells_title">请完善你的个人信息</div>
    <div class="weui_cells weui_cells_form">
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label class="weui_label">姓名:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name='realname' id='realname' value="{$member['realname']}" placeholder="请输入您的真实姓名" />
            </div>
        </div>
        <!--  <div class="weui_cell weui_cell_select weui_select_after">
            <div class="weui_cell_hd">
                <label class="weui_label">身份:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <select class="weui_select" name="type" id="type" style="margin-left:-15px;">
                    <option value="1">业主</option>
                    <option value="2">租客</option>
                    <option value="3">游客</option>
                    <option value="4">家属</option>
                </select>
            </div>
        </div> -->
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label for="" class="weui_label">手机:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name='mobile' id='mobile' placeholder="请输入与物业处所留手机号一致" />
            </div>
        </div>
        {if $set['room_enable']}
        <div class="weui_cell weui_cell_select weui_select_after">
            <div class="weui_cell_hd">
                <label class="weui_label">房号:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <select class="weui_select" name="address" id="address" style="margin-left:-15px;">
                    <!-- {loop $rooms $room}
                    <option value="{$room['room']}">{$room['room']}</option>
                {/loop} -->
                </select>
            </div>
        </div>
        {else}
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label for="" class="weui_label">房号:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary" style="width:50px">
                <div style="float:left">
                    <input style='height: 28px;width:40px' type="text" name='build' id='build' />
                </div>
                <div style="float:left;color:#a9a9a9;font-size:14px;line-height:28px">栋/幢</div>&nbsp;
                <div style="float:left">
                    <input style='height: 28px;width:40px;' type="text" name='unit' id='unit' />
                </div>
                <div style="float:left;color:#a9a9a9;font-size:14px;line-height:28px">单元</div>&nbsp;
                <div style="float:left">
                    <input style='height: 28px;width:40px;' type="text" name='room' id='room' />
                </div>
                <div style="float:left;color:#a9a9a9;font-size:14px;line-height:28px">室</div>
            </div>
        </div>
        {/if} {if $set['code_status']}
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label for="" class="weui_label">注册码:</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text" name='code' id='code' placeholder="请输入物业提供给您的注册码" />
            </div>
        </div>
        {/if} {if $sms['verifycode']}
        <div class="weui_cell">
            <div class="weui_cell_hd">
                <label class="weui_label">验证码</label>
            </div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="number" placeholder="收到验证码" name="verifycode" id="verifycode" />
            </div>
            <div class="weui_cell_ft">
                <button type="button" id="verifyCodeBtn" class="weui_btn weui_btn_mini weui_btn_primary" onclick="sendVerifyCode();">获取验证码</button>
            </div>
        </div>
        {/if}
        <!-- <div class="weui_cell">
            <div class="weui_cell_bd weui_cell_primary">
                <textarea class="weui_textarea" placeholder="请输入备注" rows="3" name='remark' id='remark'></textarea>
                <div class="weui_textarea_counter"><span>0</span>/200</div>
            </div>
        </div> -->
    </div>
    <div class="bd spacing" style="text-align:center;margin-top:10px;">
        <a href="javascript:;" class="weui_btn weui_btn_primary" id="showToast" style="margin-bottom:-10px;width:80%">确认注册</a>
        <a href="javascript:history.go(-1)" class="weui_btn weui_btn_default" style="margin-bottom:40px;width:80%">返回</a>
    </div>
    <div id="toast" style="display: none;">
        <div class="weui_mask_transparent"></div>
        <div class="weui_toast">
            <i class="weui_icon_toast"></i>
            <p class="weui_toast_content"></p>
        </div>
    </div>
    <div class="weui_dialog_alert" id="dialog2" style="display: none;">
        <div class="weui_mask"></div>
        <div class="weui_dialog">
            <div class="weui_dialog_hd"><strong class="weui_dialog_title"></strong></div>
            <div class="weui_dialog_bd"></div>
            <div class="weui_dialog_ft">
                <a href="javascript:;" class="weui_btn_dialog primary">确定</a>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="{$_W['siteroot']}app/resource/js/lib/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
    $(function() {
        $("#showToast").click(function(event) {
            var realname = $("#realname").val();
            if (realname == '') {
                alert('请填写真实姓名');
                return false
            };
            var mobile = $("#mobile").val();
            if (mobile == '') {
                alert('请填写真实手机号码');
                return false
            };
            if (!(/^1[3|5|7|4|5|8|][0-9]\d{4,8}$/.test(mobile))) {
                alert("不是完整的11位手机号或者正确的手机号前七位");
                return false;
            }
            var code = $("#code").val();
            if (code == '') {
                alert('注册码必填');
                return false
            };

            var address = $("#address").val();
            var build = $("#build").val();
            if (build == '') {
                alert('请填写正确的楼栋号');
                return false
            };
            var room = $("#room").val();
             if (room == '') {
                alert('请填写正确的房间号');
                return false
            };
            var verifycode = $("#verifycode").val();
            var regionid = "{$_GPC['regionid']}";
            var type = $("#type").val();
            var remark = $("#remark").val();

            $.ajax({
                url: "{php echo $this->createMobileUrl('register',array('op' => 'member'))}",
                dataType: 'json',
                data: {
                    realname: realname,
                    mobile: mobile,
                    build: build,
                    room: room,
                    remark: remark,
                    regionid: regionid,
                    verifycode: verifycode,
                    type: type,
                    code: code,
                    address:address
                },
                success: function(s) {
                    if (s.status == 1) {
                        $('.weui_toast_content').text('注册成功');
                        $('#toast').show();
                        setTimeout(function() {
                            $('#toast').hide();
                            window.location.href = "{php echo $this->createMobileUrl('home')}";
                        }, 3000);
                    }
                    if (s.status == 2) {
                        $('.weui_toast_content').text('注册失败,该手机号码已经注册');
                        $('#toast').show();
                        setTimeout(function() {
                            $('#toast').hide();
                            window.location.reload();
                        }, 3000);
                    }
                    if (s.status == 3) {

                        $('.weui_dialog_bd').text('验证码错误');
                        $('#dialog2').show();
                        setTimeout(function() {
                            $('#dialog2').hide();
                            window.location.reload();
                        }, 3000);

                    }
                    if (s.status == 4) {

                        $('.weui_dialog_bd').text('注册码不对,请联系物业重新获取');
                        $('#dialog2').show();
                        setTimeout(function() {
                            $('#dialog2').hide();
                            window.location.reload();
                        }, 3000);

                    }
                    if (s.status == 5) {

                        $('.weui_dialog_bd').text('与物业预留的手机号码不一致,请重新输入');
                        $('#dialog2').show();
                        setTimeout(function() {
                            $('#dialog2').hide();
                            window.location.reload();
                        }, 3000);

                    }
                    if (s.status == 6) {
                        $('.weui_toast_content').text('修改成功,请耐心等待管理员审核');
                        $('#toast').show();
                        setTimeout(function() {
                            $('#toast').hide();
                            window.location.href = "{php echo $this->createMobileUrl('register',array('op' => 'region'))}";
                        }, 3000);
                    }
                    if (s.status == 7) {
                        $('.weui_toast_content').text('请选择房号');
                        $('#toast').show();
                        setTimeout(function() {
                            $('#toast').hide();
                           
                        }, 3000);
                    }
                     if (s.status == 8) {
                        $('.weui_toast_content').text('请输入正确的楼栋号和房间号');
                        $('#toast').show();
                        setTimeout(function() {
                            $('#toast').hide();
                           
                        }, 3000);
                    }

                }
            })


        });
        $("#mobile").keyup(function() {
            var mobile = $("#mobile").val();
            // var leng = mobile.length;
            // if (leng == 11) {alert(mobile);};

            var regionid = "{$_GPC['regionid']}";
            if (mobile) {
                $.ajax({
                    url: "{php echo $this->createMobileUrl('register',array('op' => 'room'))}",
                    dataType: 'json',
                    data: {
                        mobile: mobile,
                        regionid: regionid
                    },
                    success: function(s) {
                        var data = JSON.parse(s.content);

                        if (s.status == 1) {
                            $.each(data, function(index, value) {
                                var content = "<option value=\"" + value.room + "\" >" + value.room + "</option>";
                                $("#address").html(content);
                            });


                        };
                        if (s.status == 2) {
                            $('.weui_dialog_bd').text('与物业预留的手机号码不一致,请联系物业修改。');
                            $('#dialog2').show();
                            setTimeout(function() {
                                $('#dialog2').hide();
                                window.location.reload();
                            }, 3000);
                        };

                    }
                })
            };

        });
    })
    </script>
    <script type="text/javascript">
    function sendVerifyCode() {
        var mobile = $('#mobile').val();
        if (!mobile) {
            alert('请输入您的手机号码！');
            return false;
        }
        if (mobile.search(/^1[3|5|7|4|5|8|][0-9]\d{4,8}$/) == -1) {
            alert('请输入正确的手机号码！');
            return false;
        }
        $('#verifyCodeBtn').addClass('active');
        $('#verifyCodeBtn').attr('disabled', true);
        var countdown = 60;
        timer = setInterval(function() {
            $('#verifyCodeBtn').html(countdown--);
            if (countdown == 0) {
                $('#verifyCodeBtn').removeClass('active');
                $('#verifyCodeBtn').html('重新发送');
                clearInterval(timer);
                $('#verifyCodeBtn').attr('disabled', false);
            }
        }, 1000);
        $.getJSON("{php echo $this->createMobileUrl('verifycode','',true)}&mobile=" + mobile + '&type=verify',
            function(s) {
                if (s.status == 2) {
                    $('.weui_dialog_bd').text('号码已经注册,请更新号码');
                    $('#dialog2').show();
                    setTimeout(function() {
                        $('#dialog2').hide();
                        window.location.reload();
                    }, 3000);

                };
            });
    }
    </script>
</body>

</html>
